﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Office.Interop.Word;

namespace WFL.Office.Word
{
    public class WordHyperlink
    {
        private readonly object _lock = new object();

        public string Name
        {
            get { return _hyperlink.Name; }
        }

        public string Address
        {
            get { return _hyperlink.Address; }
            set { _hyperlink.Address = value; }
        }

        public string SubAddress
        {
            get { return _hyperlink.SubAddress; }
            set { _hyperlink.SubAddress = value; }
        }

        public string ScreenTip
        {
            get { return _hyperlink.ScreenTip; }
            set { _hyperlink.ScreenTip = value; }
        }

        public string TextToDisplay
        {
            get { return _hyperlink.TextToDisplay; }
            set { _hyperlink.TextToDisplay = value; }
        }

        public string Target
        {
            get { return _hyperlink.Target; }
            set { _hyperlink.Target = value; }
        }

        private WordRange _range;
        public WordRange Range
        {
            get
            {
                if (_range == null)
                {
                    lock (_lock) { if (_range == null) { _range = new WordRange(_hyperlink.Range) { Document = Document }; } }
                }
                return _range;
            }
        }

        private WordShape _shape;
        public WordShape Shape
        {
            get
            {
                if (_shape == null)
                {
                    lock (_lock) { if (_shape == null) { _shape = new WordShape(_hyperlink.Shape); } }
                }
                return _shape;
            }
        }

        public HyperlinkType Type
        {
            get { return (HyperlinkType)_hyperlink.Type; }
        }

        private Hyperlink _hyperlink;

        public WordDocument Document
        {
            get;
            internal set;
        }

        internal WordHyperlink(Hyperlink hyperlink)
        {
            _hyperlink = hyperlink;
        }
    }
}
